package org.raymond.iworks.study.spring.repository;

import org.raymond.iworks.study.spring.entity.GapTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Map;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public interface LockSQLRepository extends JpaRepository<GapTable, Long> {
    /**
     * INSERT INTO gap_table (id, letter, num) VALUES (1, 'd', 3);
     * INSERT INTO gap_table (id, letter, num) VALUES (2, 'g', 6);
     * INSERT INTO gap_table (id, letter, num) VALUES (3, 'j', 8);
     */

    @Query(value="select * from gap_table where id=2", nativeQuery = true)
    Map<String, Object> queryUIdxField();

    @Query(value="select * from gap_table where num=?1", nativeQuery = true)
    Map<String, Object> queryNonUIdxField(int num);

    @Modifying(clearAutomatically = true)
    @Query(value="update gap_table set num=5 where num='6'", nativeQuery = true)
    int updateGap();

    @Query(value = "select count(1) from gap_table", nativeQuery = true)
    int countGap();

    @Modifying(clearAutomatically = true)
    @Query(value = "insert into gap_table (id, letter, num) values(4, '', 6)", nativeQuery = true)
    int insertGap();

    @Modifying(clearAutomatically = true)
    @Query(value="delete from gap_table", nativeQuery=true)
    int remove();
    @Modifying(clearAutomatically = true)
    @Query(value = "insert into gap_table (id, letter, num) values(1, 'd', 3)", nativeQuery = true)
    int insert1();
    @Modifying(clearAutomatically = true)
    @Query(value = "insert into gap_table (id, letter, num) values(2, 'g', 6)", nativeQuery = true)
    int insert2();
    @Modifying(clearAutomatically = true)
    @Query(value = "insert into gap_table (id, letter, num) values(3, 'j', 8)", nativeQuery = true)
    int insert3();
}
